<?php
namespace app\service;
/**
 * @Description:
 * @Author: Chern
 * @Date: 2023/6/28
 * @Time: 16:36
 */

class Token {

    private $name;

    private $passowrd;

    private $salt; //加密盐 注册生成

    private $token;

    private $info;

    private $expireTime = '86400'; //Token过期时间

    public function __construct($username='',$passowrd='',$salt='')
    {

        $this->name = $username;

        $this->passowrd = $passowrd;

        $this->salt = $salt;

        $this->info = $username.$passowrd.$salt;
    }

    /*
     * 生成Token
     * return string
     */

    public function createToekn()
    {
       return $this->token = hash_hmac('md5',$this->info,$this->salt);
    }


    /*
     * 验证token
     * @param sign
     */

    public function checkToekn()
    {

    }


    /*
     * 获取Token过期时间
     */

    public function getTokenExpireTime()
    {
        return $this->expireTime;
    }

    /*
     * 验证token是否过期
     */

    public function VTokenExpireTime($expireTime)
    {
        if (empty($expireTime) || $expireTime < time()){
            return false;
        }

        return true;
    }


}